#include "date_time_plot_controller.h"

DateTimePlotController::DateTimePlotController(QCustomPlot *plot,
    QObject *parent)
    : PlotController{plot, parent}
{
    initPlot();
}

DateTimePlotController::~DateTimePlotController()
{
    m_plot = nullptr;
}

void DateTimePlotController::append(double timestamp, double value)
{
    addData(0, timestamp, value);
    setAxisRange(0, timestamp-5, timestamp+5);
}

void DateTimePlotController::append(QDateTime dateTime, double value)
{
    append(QCPAxisTickerDateTime::dateTimeToKey(dateTime), value);
}



void DateTimePlotController::initPlot()
{
    assert(m_plot != nullptr);
    m_dateTimeTicker = QSharedPointer<QCPAxisTickerDateTime>(new QCPAxisTickerDateTime);
    m_dateTimeTicker->setDateTimeFormat("yyyy-MM-dd\nhh:mm:ss");

    m_plot->xAxis->setTicker(m_dateTimeTicker);
    m_plot->yAxis->setRange(-15.2, 15.2);
}
